//
//  NetImagerController.m
//  NetImager
//
//  Created by li hongliang on 10-9-9.
//  Copyright 2010 sweet-home. All rights reserved.
//

#import "NetImagerController.h"


@implementation NetImagerController



- (void) loadView {
//	[super loadView];	
	UIView *spView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
	spView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
	spView.backgroundColor = [UIColor whiteColor];
	self.view = spView;	
	
	UIImage *image = [UIImage imageNamed:@"logo.png"];
	UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
	[image release];
	imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
	imageView.contentMode = UIViewContentModeScaleAspectFit;
	imageView.alpha = 0.3f;
	imageView.center = CGPointMake(self.view.center.x, self.view.center.y-30.0f);;
	
	[spView addSubview:imageView];
	
	[UIView beginAnimations:nil context:spView];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
	[UIView setAnimationDuration:3];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
	imageView.alpha = 1.0f;
	[UIView commitAnimations];
}

- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
	UIView *spView = context;
	[UIView beginAnimations:nil context:spView];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
	[UIView setAnimationDuration:1];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(animationDidStop2:finished:context:)];
	spView.alpha = 0.3f;
	[[spView.subviews objectAtIndex:0] setAlpha:0.3f];
	[UIView commitAnimations];
}

- (void) animationDidStop2:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
	pickerController = [[[ImagePickerController alloc] init] autorelease];
	pickerController.title = @"NetImager";
	pickerController.delegate = self;
	pickerController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;	
	[self presentModalViewController:pickerController animated:YES];
}


- (void) toPickerController:(id) sender
{
	[pickerController dismissModalViewControllerAnimated:YES];
}



- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
	//[self dismissModalViewControllerAnimated:YES];
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
	ImageSenderController * newSenderController = [[ImageSenderController alloc] init];
	if(senderController != nil)
	{
		[senderController release];
		senderController = nil;
	}
	senderController = newSenderController;
	senderController.image = [info objectForKey:UIImagePickerControllerOriginalImage];
	senderController.delegate = self;
	
	UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:senderController] autorelease];
	
	nav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[pickerController presentModalViewController:nav animated:YES];	
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void) viewWillAppear:(BOOL)animated 
{
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
	
}


@end
